import java.awt.Color;
import java.awt.Graphics;

/**
 * A way to represent each grid square as a JPanel
 * @author Matthew Lingelbach
 * @version 1.0
 */
public class Tile extends javax.swing.JPanel {
	private int x;
	private int y;
	private int iPos, jPos;
	private boolean clicked;	// Has the square been clicked/toggled on?
	private Color color = Color.RED;

	/**
	 * Creating a new Tile creates a JPanel
	 * with a background of white at the given 
	 * x and y position.
	 * @param x
	 * @param y
	 */
	public Tile(int x, int y, int iPos, int jPos){
		super();
		this.x = x;
		this.y = y;
		this.iPos = iPos;
		this.jPos = jPos;
		clicked = false;
		setBackground(new java.awt.Color(255,255,255));
		setBounds(x, y, 8, 8);
	}

	/**
	 * Draws/removes an oval in the panel if the tile is
	 * toggled on/off.
	 */
	public void paintComponent( Graphics g )
	{
		super.paintComponent( g );
		super.setForeground(color);
		if(clicked){
			g.fillOval( 0, 0, 8, 8 );
		}else{
			g.clearRect(0, 0, 8, 8);
		}
	}

	/**
	 * Repaints the JPanel
	 */
	public void draw()
	{
		repaint();
	}

	/* Getters and Setters */
	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}
	
	public int getI(){
		return iPos;
	}
	
	public int getJ(){
		return jPos;
	}

	public boolean isClicked() {
		return clicked;
	}
	
	public int getColor(){
		if(color.equals(Color.RED))
			return 0;
		else 
			return 1;
	}

	public void setClicked(boolean clicked, int colorNum) {
		this.clicked = clicked;
		if(colorNum == 0)
			color = Color.RED;
		else
			color = Color.BLUE;
	}
	/* End Getters and Setters */
}
